import $ from 'jquery'
const layer = layui.layer

const button = document.querySelector('.button')
const button2 = document.querySelector('.button2')
let layerIndex
const content = $('#device-detail')
const clickEvent = () => {
  if (layerIndex !== void 0) layer.close(layerIndex)

  // 必须在此块级作用域内定义contentClone,若在外部定义, end的回调闭包捕捉到的外部contentClone始终指向最新那一个
  const contentClone = content.clone().appendTo('body')
  layerIndex = layer.open({
    type: 1,
    title: false,
    closeBtn: 1,
    area: '300px',
    shade: 0,
    content: contentClone,
    end: function () {
      contentClone.remove()
    },
  })
}
button.addEventListener('click', clickEvent)
button2.addEventListener('click', clickEvent)
